package com.xinjie.www.servlet;

import com.xinjie.www.service.user.UserService;
import com.xinjie.www.service.user.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class RegisterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String registerName = req.getParameter("registerName");
        String password = req.getParameter("registerPassword");
        String sex = req.getParameter("sex");
        String birthday = req.getParameter("birth");
        String sign = req.getParameter("sign");
        UserService userService = new UserServiceImpl();
        boolean b = false;
        if (!"".equals(registerName) && !"".equals(password) && !"".equals(sex) && !"".equals(birthday) && !"".equals(sign)) {
            b = userService.registerUser(registerName, password, sex, birthday, sign);
        }
        if (b) {
            req.getSession().setAttribute("registerSuccess", "注册成功，请重新登录");
            resp.sendRedirect("/login.jsp");
        } else {
            req.getSession().setAttribute("registerLose", "注册失败，请重新注册");
            resp.sendRedirect("/register.jsp");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
